<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/js/plugins/ckeditor/ckeditor.js"></script>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "daily" />
        <#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>日报管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/daily/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword"  placeholder="请输入标题">
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i>查询</button>
                        <a href="javascript:void(-1);" class="btn btn-success inputDailyBtn">
                            <span class="glyphicon glyphicon-plus"></span>添加日报文章
                        </a>
                    </div>
                </form>
            </div>
            <script>
                $("#keyword").val("${(qo.keyword)!}");
            </script>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>标题</th>
                        <th>封面</th>
                        <th>副标题</th>
                        <th>发布时间</th>
                        <th>状态</th>
                        <th></th>
                    </tr>

                    </thead>
                    <tbody>
					<#list info.list as entity>
                    <tr>
                        <td>${entity_index +  1}</td>
                        <td>${entity.title!""}</td>
                        <td><img src='${entity.coverUrl!"" }' width="100px"/></td>
                        <td>${entity.subtitle!""}</td>
                        <td>${entity.creatTime?string("yyyy-MM-dd")}</td>
                        <td>${entity.stateName!""}</td>
                        <td><a class="inputDailyBtn" data-json='${entity.json}'>编辑</a></td>
                    </tr>
					</#list>
                    </tbody>
                </table>
                <#include "../common/page.ftl"/>
            </div>
        </div>
    </div>
</div>
<div id="dailyModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="dailyForm" class="form-horizontal" method="post" action="/daily/saveOrUpdate.do" enctype="multipart/form-data" style="margin: -3px 118px">
                    <input id="strategyDetailId" type="hidden" name="id" />
                    <input id="reset" type="reset" style="display: none"/>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">标题</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" placeholder="标题">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">副标题</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subtitle" placeholder="副标题">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="200px"/>
                            <input type="hidden" name="coverUrl">
                            <input type="file" class="form-control"  name="file" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态</label>
                        <div class="col-sm-6">
                            <select id="auditState" class="form-control" name="state">
                                <option value="-1">禁用</option>
                                <option value="0">草稿</option>
                                <option value="1">发布</option>
                            </select>
                        </div>
                    </div>

                    <textarea name="dailyContent.content" id="editor" rows="30" cols="200">

                    </textarea>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveDailyBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

<style>
    #strategyDetailModal img {
        width: 100%;
    }
</style>
<script>
    <#--$("#pagination").twbsPagination({
        totalPages:${info.pages}||1,
        visiblePages: 5,
        startPage:${info.pageNum}||1,
        first: "首页",
        prev: "上一页",
        next: "下一页",
        last: "尾页",
        onPageClick: function (event, page) {
            $("#currentPage").val(page);
            $("#searchForm").submit();
        }
    });-->


    //初始化文本编辑器
    var editor = CKEDITOR.replace( 'editor' );

    $("#query").click(function () {
        $("#currentPage").val(1);
        $("#searchForm").submit();
    });




    $(".inputDailyBtn").click(function () {

        //增加日报是先清空模态框数据
        $(":input").val("");
        $("#coverUrl").attr("src","");
      //  editor.setData(null);
        var json = $(this).data("json");

        //模态框处理
            if(json){
                //jaon不为null 所名是编辑操作
                $("#dailyForm input[name='id']").val(json.id);
                $("#dailyForm input[name='title']").val(json.title);
                $("#coverUrl").attr("src",json.coverUrl);
                $("#dailyForm input[name='coverUrl']").val(json.coverUrl);
                $("#dailyForm input[name='subtitle']").val(json.subtitle);
                $("#dailyForm select[name='state']").val(json.state);

                //回显文章内容到ckeditor
                console.log(editor);

                editor.setData(json.content);

            }

            $("#dailyModal").modal("show");
        });


    $("#saveDailyBtn").click(function () {
        var text = editor.getData();
        $("#dailyForm textarea[name='dailyContent.content']").html(text);
        $("#dailyForm").submit();
    });



</script>
</body>
</html>